package TankGame05;

public class Bullet extends Thread {
    private int x;
    private int y;
    private int direct;
    private int speed = 20;
    private boolean isLive = true;//查看子弹线程是否还存活

    public Bullet(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    @Override
    public void run() {
        while (isLive){
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            switch (direct) {
                case 0: y -= speed;
                        break;
                case 1: x += speed;
                        break;
                case 2: y += speed;
                        break;
                case 3: x -= speed;
                        break;
            }
            System.out.println("x = "+ x +"y = "+ y);
            if(!(x < 1000 && x > 0 && y > 0&& y < 750)){
                System.out.println("子弹被销毁了...");
                isLive = false;
                break;
            }
        }
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getDirect() {
        return direct;
    }

    public void setDirect(int direct) {
        this.direct = direct;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public boolean getIsLive() {
        return isLive;
    }

    public void setIsLive(boolean live) {
        isLive = live;
    }
}
